package me.chan.stream;

import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;

public class OtherTypeStream {

	public static void main(String[] args) {
		//create a string stream by using the static method Stream.of 
		Stream<String> stream = Stream.of("Java", "In", "Action");
		stream.map(String::toUpperCase).forEach(System.out::println);
		
		//create an empty stream
		Stream<String> emptyStream = Stream.empty();
		System.out.println(emptyStream.collect(toList()));
		
		int[] numbers = {1,2,3,4,5};
		int sum = Arrays.stream(numbers).sum();
		System.out.println(sum);
		
		long uniqueWords = 0;
		try (Stream<String> lines = Files.lines(Paths.get("../stream.txt"), Charset.defaultCharset())) {
			uniqueWords = lines.flatMap(line -> Arrays.stream(line.split(" "))).distinct().count();
			System.out.println(uniqueWords);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
